package com.huawei.Galenus.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huawei.Galenus.fabric.FabricHelper;
import com.huawei.Galenus.service.FabricService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

@Service("DemoService")
public class FabricServiceImpl implements FabricService {

    @Autowired
    private Environment environment;

    FabricHelper helper = FabricHelper.getInstance();

    @Override
    public JSONObject ssaQuery(String method, String[] params) {
        helper.setConfigCtx(environment.getProperty("ssa-config-path"));
        JSONObject payload = helper.queryBlockchain(method, params);
        return payload;
    }

    @Override
    public JSONObject ssaInvoke(String method, String[] params) {
        helper.setConfigCtx(environment.getProperty("ssa-config-path"));
        JSONObject jsonObject = helper.invokeBlockchain(method, params);
        return jsonObject;
    }

    @Override
    public JSONObject songQuery(String method, String[] params) {
        helper.setConfigCtx(environment.getProperty("song-config-path"));
        JSONObject payload = helper.queryBlockchain(method, params);
        return payload;
    }

    @Override
    public JSONObject songInvoke(String method, String[] params) {
        helper.setConfigCtx(environment.getProperty("song-config-path"));
        JSONObject jsonObject = helper.invokeBlockchain(method, params);
        return jsonObject;
    }

}
